/*
class Node{
    public int val;
    public Node left;
    public Node right;
    public Node(int val){
        this.val=val;
    }
}
public class BinarySearchTree {
    public static Node root=null;

    public Node search(int val){
        if(root==null){
            return null;
        }
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                cur=cur.right;
            }else if(cur.val==val){
                return cur;
            }else{
                cur=cur.left;
            }
        }
        return null;
    }

    public boolean insert(int val){
        if(root==null){
            root=new Node(val);
            return true;
        }
        Node parent=null;
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                parent=cur;
                cur=cur.right;
            }else if(cur.val==val){
                return false;
            }else{
                parent=cur;
                cur=cur.left;
            }
        }
        Node node=new Node(val);
        if(parent.val<node.val){
            parent.right=node;
        }else{
            parent.left=node;
        }
        return true;
    }

    public void remove(int val){
        if(root==null){
            return;
        }
        Node parent=null;
        Node cur=root;
        while(cur!=null){
            if(cur.val<val){
                parent=cur;
                cur=cur.right;
            }else if(cur.val==val){
                removeNode(parent,cur);
                break;
            }else{
                parent=cur;
                cur=cur.left;
            }
        }
    }

    public void removeNode(Node parent,Node cur){
        if(cur.left==null){
            if(cur==root){
                root=root.right;
            }else if(parent.left==cur){
                parent.left=cur.right;
            }else{
                parent.right=cur.right;
            }
        }else if(cur.right==null){
            if(root==null){
                root=root.left;
            }else if(parent.left==cur){
                parent.left=cur.left;
            }else{
                parent.right=cur.left;
            }
        }else{
            Node targetParent=cur;
            Node target=cur.left;
            while(target.right!=null){
                targetParent=target;
                target=target.right;
            }
            cur.val=target.val;
            if(targetParent.left==target){
                targetParent.left=target.left;
            }else{
                targetParent.right=target.left;
            }
        }
    }

    public void inOrder(Node root){
        if(root==null){
            return;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }

    public static void main(String[] args) {
        int []array={44,33,22,11,23,34,2,1};
        BinarySearchTree binarySearchTree=new BinarySearchTree();
        for (int i = 0; i < array.length; i++) {
            binarySearchTree.insert(array[i]);
        }
        binarySearchTree.inOrder(root);
        System.out.println();
        System.out.println(binarySearchTree.insert(1));
        System.out.println();
        binarySearchTree.remove(1);
        binarySearchTree.inOrder(root);

    }

}

*/
